/**
 * 
 */
package labox.innovation.gameserver.network.clientpackets;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import labox.innovation.gameserver.model.ConsignmentItem;
import labox.innovation.gameserver.model.ConsignmentManager;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.model.itemcontainer.ConsignmentWarehouse;
import labox.innovation.gameserver.network.SystemMessageId;
import labox.innovation.gameserver.network.serverpackets.ConsignmentUIPacket;
import labox.innovation.gameserver.network.serverpackets.SystemMessage;

/**
 * @author ljsh
 * @date 2010-5-5
 * @version 1.0
 * @description  物品下架
 */
public class RequestItemShelf extends L2GameClientPacket {
	private static Logger _log=LoggerFactory.getLogger(RequestItemShelve.class);
	private static final String _C_REQUESTITEMSHELF = "_C_RequestItemShelf";

	/**
	 * 物品ID
	 */
	private long itemid;

	/* (non-Javadoc)
	 * @see labox.innovation.gameserver.network.clientpackets.L2GameClientPacket#getType()
	 */
	@Override
	public String getType() {
		return _C_REQUESTITEMSHELF;
	}

	/* (non-Javadoc)
	 * @see labox.innovation.gameserver.network.clientpackets.L2GameClientPacket#readImpl()
	 */
	@Override
	protected void readImpl() {
		itemid = readLong();

	}

	/* (non-Javadoc)
	 * @see labox.innovation.gameserver.network.clientpackets.L2GameClientPacket#runImpl()
	 */
	@Override
	protected void runImpl() {
		FuzePcInstance active = getClient().getActiveChar();
		if (active == null) {
			return;
		}
		ConsignmentWarehouse house = ConsignmentManager.getConsignmentWarehouse(active.getObjectId());
		if (house == null) {
			return;
		}
		ConsignmentItem item = house.getConsignmentItem(itemid);
		if (item == null) {
			active.sendPacket(new SystemMessage(SystemMessageId.THIS_KIND_ITEM_CANNOT_FOUND_IN_THE_WAREHOUSE));
			return;
		}
		item.setShelve(false);
		item.getTimer().cancel();
		ConsignmentManager.shelf(item);
		active.sendPacket(new ConsignmentUIPacket(active));
		active.sendPacket(new SystemMessage(SystemMessageId.SHELF_SUCCESS));
	}

}
